package com.lishanyang.spring.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;


public class AroundLogAdvice implements MethodInterceptor {
    private Logger logger=Logger.getLogger(AroundLogAdvice.class);
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        long beginTime=System.currentTimeMillis();
        Thread.sleep(10);
        methodInvocation.proceed();
        long endTime=System.currentTimeMillis();
        //获取被调用的方法名
        String targetMethodName=methodInvocation.getMethod().getName();
        //日志格式字符串
        String logInfoText="环绕通知："+targetMethodName+"方法调用前时间"+beginTime+"毫秒，"+"调用后时间"+endTime+"毫秒";
        logger.info(logInfoText);
        return null;
    }
}
